package com.dragon.mmochat.service;

import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.MmochatMain;
import com.dragon.mmochat.message.Mmochat_10_10C;
import com.dragon.mmochat.message.Mmochat_10_11S;
import com.dragon.mmochat.message.Mmochat_10_12S;
import com.dragon.mmochat.message.Mmochat_10_13S;
import com.dragon.mmochat.message.Mmochat_10_14S;
import com.dragon.mmochat.message.Mmochat_10_15S;
import com.dragon.mmochat.message.Mmochat_10_16S;
import com.dragon.mmochat.message.Mmochat_10_17C;
import com.dragon.mmochat.message.Mmochat_10_18C;
import com.dragon.mmochat.message.Mmochat_10_19C;
import com.dragon.mmochat.message.Mmochat_10_1S;
import com.dragon.mmochat.message.Mmochat_10_21C;
import com.dragon.mmochat.message.Mmochat_10_2C;
import com.dragon.mmochat.message.Mmochat_10_2S;
import com.dragon.mmochat.message.Mmochat_10_3C;
import com.dragon.mmochat.message.Mmochat_10_4C;
import com.dragon.mmochat.message.Mmochat_10_4S;
import com.dragon.mmochat.message.Mmochat_10_5C;
import com.dragon.mmochat.message.Mmochat_10_6C;
import com.dragon.mmochat.message.Mmochat_10_7C;
import com.dragon.mmochat.message.Mmochat_10_8C;
import com.dragon.mmochat.message.Mmochat_10_9C;
import com.dragon.mmochat.message.Mmochat_1_1S;
import com.dragon.mmochat.message.Mmochat_5_1S;
import com.dragon.mmochat.model.MmochatOfflineMsg;
import com.dragon.mmochat.model.enumType.MmochatPropType;
import com.dragon.mmochat.model.enumType.MmochatQickStartType;
import com.dragon.mmochat.model.enumType.MmochatRoleStateType;
import com.dragon.mmochat.model.enumType.MmochatServerType;
import com.dragon.mmochat.model.map.MmochatMap;
import com.dragon.mmochat.model.object.MmochatCommonObject;
import com.dragon.mmochat.model.object.MmochatPackageGrid;
import com.dragon.mmochat.model.object.MmochatProp;
import com.dragon.mmochat.model.role.MmochatFriend;
import com.dragon.mmochat.model.role.MmochatPet;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.service.MmochatMainService.CheckDeadMan;
import com.dragon.mmochat.util.CreateTlvWin;
import com.dragon.mmochat.util.MmochatUtil;
import com.skymobi.handler.SkymobiHandler;
import com.skymobi.message.SkymobiProtocolMessage;
import com.skymobi.message.widget.AddDataTLV;
import com.skymobi.message.widget.AddEditBoxTLV;
import com.skymobi.message.widget.ClearDataTLV;
import com.skymobi.message.widget.CloseWinTLV;
import com.skymobi.message.widget.CreateEditBoxTLV;
import com.skymobi.message.widget.CreateMsgBoxTLV;
import com.skymobi.message.widget.CtrlTLVStructureRequest;
import com.skymobi.message.widget.SendDataTLV;
import com.skymobi.message.widget.ShowPopupMenuTLV;
import com.skymobi.message.widget.ShowWaitingMsgBoxTLV;
import com.skymobi.message.widget.TLVStructure;
import com.skymobi.message.widget.WinType;
import com.skymobi.service.SkymobiService;
import com.skymobi.util.Text;

//好友系统
public class MmochatFriendService {
	private static Logger log = LoggerFactory
			.getLogger(MmochatFriendService.class);

	public static ScheduledExecutorService checkOfflineMsgThread = Executors
			.newScheduledThreadPool(1);

	// 离线消息:<接收者roleId, Map<发送者roleId, 离线消息>>
	public static Map<Integer, Map<Integer, MmochatOfflineMsg>> offlineMsgs = new ConcurrentHashMap<Integer, Map<Integer, MmochatOfflineMsg>>();

	// 玩家私聊记录:<"大的roleId+小的roleId",聊天内容>
	public static Map<String, String> privateChatMap = new ConcurrentHashMap<String, String>();

	public MmochatFriendService() {
		if (!MmochatMain.openMergeServer) {
			offlineMsgs.clear();
			checkOfflineMsgThread.scheduleWithFixedDelay(new CheckOfflineMsg(),
					10, 10, TimeUnit.HOURS);
		}
	}

	// 去除过期的离线消息
	public class CheckOfflineMsg implements Runnable {
		@Override
		public void run() {
			for (Entry<Integer, Map<Integer, MmochatOfflineMsg>> entry : offlineMsgs
					.entrySet()) {
				Map<Integer, MmochatOfflineMsg> msgMaps = entry.getValue();
				if (msgMaps != null) {
					for (MmochatOfflineMsg msg : msgMaps.values()) {
						if (System.currentTimeMillis() - msg.getUpdateTime() > MmochatConstant.offlineMsgLife) {
							// 此消息已过期
							msgMaps.remove(msg.getSendRoleId());
						}
					}
					if (msgMaps.size() == 0) {
						offlineMsgs.remove(entry.getKey());
					}
				}
			}
		}
	}

	// 增加离线消息，返回false则留言人数已达上限
	public static boolean addPlayerOfflineMsgToFriend(int receiveRoleId,
			int sendRoleId, String title, String msg) {
		if (msg == null) {
			return true;
		}
		Map<Integer, MmochatOfflineMsg> msgMap = offlineMsgs.get(receiveRoleId);
		if (msgMap == null) {
			msgMap = new ConcurrentHashMap<Integer, MmochatOfflineMsg>();
		}
		MmochatOfflineMsg targetMsg = msgMap.get(sendRoleId);
		if (targetMsg == null) {
			if (msgMap.size() >= MmochatConstant.maxOfflineMsgNum) {
				// 留言人数已达上限
				return false;
			}
			targetMsg = new MmochatOfflineMsg();
		}
		targetMsg.setSendRoleId(sendRoleId);
		targetMsg.setTitle(title);
		targetMsg.addMsg(msg);
		msgMap.put(sendRoleId, targetMsg);
		offlineMsgs.put(receiveRoleId, msgMap);

		return true;
	}

	// 读取离线消息并下发
	public static void sendOfflineMsgToPerson(MmochatPlayer me) {
		Map<Integer, MmochatOfflineMsg> msgMap = offlineMsgs
				.get(me.getRoleId());
		if (msgMap != null) {
			for (MmochatOfflineMsg msg : msgMap.values()) {
				Mmochat_10_4S pack = new Mmochat_10_4S();
				pack.setSendRoleId(msg.getSendRoleId());
				pack.setTitle(msg.getTitle());
				pack.setMsg(msg.getMsg());
				MmochatUtil.sendCommonPack(me, pack);
			}
			msgMap.clear();
			msgMap = null;
			offlineMsgs.remove(me.getRoleId());
		}
	}

	// 10.1 下发好友列表
	public static void sendFrindListToPerson(MmochatPlayer me) {
		if (me == null) {
			return;
		}

		List<MmochatFriend> myFriends = new ArrayList<MmochatFriend>();
		for (MmochatFriend friend : me.getMyDearFriends().values()) {
			MmochatPlayer myFriend = MmochatMainService.players.get(friend
					.getRoleId());
			if (myFriend != null) {
				friend.setBmpId(myFriend.getBmpId());
				friend.setName(myFriend.getName());
			}
			myFriends.add(friend);
		}

		Mmochat_10_1S pack = new Mmochat_10_1S();
		pack.setMe(me);
		pack.setMyFriends(myFriends);
		pack.setEnermies(new ArrayList<MmochatFriend>(me.getMyEnermys()
				.values()));
		MmochatUtil.sendCommonPack(me, pack);
	}

	// 更新最近联系人及好友在线离线情况
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_2(SkymobiHandler handler,
			Mmochat_10_2C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return null;
		}
		// 需要增加的联系人
		List<MmochatFriend> adds = new ArrayList<MmochatFriend>();

		for (MmochatFriend frd : me.getMyTempFriendsMap().values()) {
			if (!me.getMyTempFriendsBak().containsKey(frd.getRoleId())) {
				adds.add(frd);
			} else {
				me.getMyTempFriendsBak().remove(frd.getRoleId());
			}
		}
		// 需要删除的联系人
		List<MmochatFriend> dels = new ArrayList<MmochatFriend>(me
				.getMyTempFriendsBak().values());

		me.setMyTempFriendsBak(me.getMyTempFriendsMap());
		if (adds.size() > 0 || dels.size() > 0) {
			Mmochat_10_2S pack = new Mmochat_10_2S();
			pack.setMe(me);
			pack.setAdds(adds);
			pack.setDels(dels);
			MmochatUtil.sendCommonPack(me, pack);
		}

		// 更新在线离线情况
		if (me.getOnlineFriends().size() + me.getOfflineFriends().size() == 0) {
			return null;
		}
		List<Integer> onlines = new ArrayList<Integer>(me.getOnlineFriends()
				.values());
		List<Integer> offlines = new ArrayList<Integer>(me.getOfflineFriends()
				.values());
		Mmochat_10_16S pack = new Mmochat_10_16S();
		pack.setOnlines(onlines);
		pack.setOfflines(offlines);
		MmochatUtil.sendCommonPack(me, pack);
		me.getOnlineFriends().clear();
		me.getOfflineFriends().clear();

		return null;
	}

	// 添加好友
	public static SkymobiProtocolMessage addNewFriend(int hallState,
			MmochatPlayer me, MmochatPlayer he) {
		if (me == null) {
			return MmochatUtil.msgbox(hallState, "服务器忙,请稍候再试!");
		}
		if (he == null) {
			return MmochatUtil.msgbox(hallState, "对方当前不在线,无法添加好友!");
		}
		if (me.getRoleId() == he.getRoleId()) {
			return MmochatUtil.msgbox(hallState, "不能添加自己为好友!");
		}
		if (me.getMyDearFriends().containsKey(he.getRoleId())) {
			return MmochatUtil.msgbox(hallState, "对方已经在您的好友名单里了!");
		}
		if (me.isMyFriendsFull()) {
			return MmochatUtil.msgbox(hallState, "您的好友数已达上限,无法再增加好友!");
		}
		if (he.getMyEnermys().containsKey(me.getRoleId())) {
			return MmochatUtil.msgbox(hallState, "您在对方的黑名单中,无法添加好友!");
		}
		if (!he.isAcceptAddMeFriend()) {
			return MmochatUtil.msgbox(hallState, "对方拒绝被加好友!");
		}
		if (!he.isCheckAddMeFriend()) {
			// 对方不验证好友
			if (me.getMyEnermys().containsKey(he.getRoleId())) {
				// 从黑名单中删除
				me.getMyEnermys().remove(he.getRoleId());
			}
			MmochatFriend newFriend = me.addMyDearFriend(he);
			if (newFriend == null) {
				return null;
			}
			try {
				MmochatDao.updateMyFriendsAndEnermys(me);
			} catch (Exception e) {
				e.printStackTrace();
				return MmochatUtil.msgbox(hallState, "数据库忙,请稍候再试!");
			}
			he.addFans(me.getRoleId());

			Mmochat_10_11S pack = new Mmochat_10_11S();
			pack.setFriend(newFriend);
			pack.setMe(me);
			MmochatUtil.sendCommonPack(me, pack);

			if (!me.isAcceptAddMeFriend()) {
				MmochatChatService.sendSystemMsgToPerson(me, MmochatUtil
						.wrapColor("您设置了拒绝加为好友,对方可能无法也加您为好友。", Color.green));
			}
			MmochatChatService.sendSystemMsgToPerson(he, MmochatUtil.wrapColor(
					me.getName(), Color.yellow)
					+ "已加您为好友!");
			he.addTempFriend(me);

			return MmochatUtil.msgbox(hallState, "添加好友成功!");
		} else {
			// 需要验证好友,下发请求
			String msg = "";
			msg += MmochatUtil.wrapIcon(me.getBmpId())
					+ MmochatUtil.wrapColor(me.getName(), Color.yellow);
			msg += "(" + me.getLevel() + "级)";
			msg += "请求添加您为好友。";

			CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
			msgbox.setContent(new Text(msg));
			msgbox.setLeftName("接受");
			msgbox.setRightName("拒绝");
			msgbox.addLeftTLV(new ClearDataTLV());
			msgbox.addLeftTLV(new AddDataTLV((int) me.getRoleId()));
			msgbox.addLeftTLV(new AddDataTLV((int) 0));
			msgbox.addLeftTLV(new SendDataTLV(MmochatConstant
					.getClientModuleId(), MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_10_21, (int) he
							.getRoleId()));
			msgbox.addRightTLV(new ClearDataTLV());
			msgbox.addRightTLV(new AddDataTLV((int) me.getRoleId()));
			msgbox.addRightTLV(new AddDataTLV((int) 1));
			msgbox.addRightTLV(new SendDataTLV(MmochatConstant
					.getClientModuleId(), MmochatMain.getModuleInstID(),
					MmochatConstant.MSGCODE_MMOCHAT_C_10_21, (int) he
							.getRoleId()));

			CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(
					hallState, msgbox);
			pack.setSrcId(MmochatMain.getModuleInstID());
			pack.setDstId(MmochatConstant.getClientModuleId());
			pack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
			MmochatUtil.sendCommonPack(he, pack);

			return MmochatUtil.msgbox(hallState, "请求已发出,等待对方验证!");
		}
	}

	public static void sendMsgToPersonByFriendMessage(MmochatPlayer me,
			String msg) {
		if (me == null || msg == null) {
			return;
		}
		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text(msg));
		msgbox.setLeftName("确定");

		CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(0, msgbox);
		pack.setSrcId(MmochatMain.getModuleInstID());
		pack.setDstId(MmochatConstant.getClientModuleId());
		pack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);
		MmochatUtil.sendCommonPack(me, pack);
	}

	// 通过#键下发消息给单个玩家
	public static void sendSystemMsgToPersonByFriendMessage(MmochatPlayer me,
			String msg) {
		if (msg == null) {
			return;
		}
		msg = MmochatUtil.wrapColor("系统消息:" + msg, Color.yellow);
		sendMsgToPersonByFriendMessage(me, msg);
	}

	// 通过#键下发消息给所有在线玩家
	public static void sendSystemMsgToAllByFriendMessage(String msg) {
		if (msg == null) {
			return;
		}
		msg = MmochatUtil.wrapColor("系统消息:" + msg, Color.yellow);

		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text(msg));
		msgbox.setLeftName("确定");

		CtrlTLVStructureRequest pack = new CtrlTLVStructureRequest(0, msgbox);
		pack.setSrcId(MmochatMain.getModuleInstID());
		pack.setDstId(MmochatConstant.getClientModuleId());
		pack.setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_20);

		for (MmochatPlayer me : MmochatMainService.players.values()) {
			MmochatUtil.sendCommonPack(MmochatHandle_SendChat
					.getCommonHandler(), me, pack);
		}
	}

	// 10.3 通过名字查找方式添加好友
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_3(SkymobiHandler handler,
			Mmochat_10_3C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		String name = req.getName();
		Integer roleId = MmochatMainService.nameMap.get(name);
		if (roleId == null) {
			return MmochatUtil.msgbox(req.getHallState(), "对方当前不在线,无法添加好友!");
		}
		MmochatPlayer he = MmochatMainService.players.get(roleId);
		return addNewFriend(req.getHallState(), me, he);
	}

	// 10.4 点对点私聊
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_4(SkymobiHandler handler,
			Mmochat_10_4C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (req.getTargetRoleId() == me.getRoleId()) {
			return MmochatUtil.msgbox(req.getHallState(), "不能给自己发消息!");
		}
		if (me.getMyEnermys().containsKey(req.getTargetRoleId())) {
			// 在我的黑名单
			return MmochatUtil.msgbox(req.getHallState(),
					"对方在您的黑名单中,您无法向其发送消息!");
		}

		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());

		String msg = req.getMsg();
		if (msg.length() == 0) {
			return null;
		}
		if (msg.contains("") || msg.contains("") || msg.contains("")
				|| msg.contains("")) {
			return MmochatUtil.msgbox(req.getHallState(),
					"您的聊天内容中包含不可见字符，发送失败!");
		}

		if (System.currentTimeMillis() - me.getLastTimeOfPrivateChat() < MmochatConstant.minIntervalOfPrivateChat) {
			return MmochatUtil.msgbox(req.getHallState(), "您发言太快了，请先喝口水!");
		}
		me.setLastTimeOfPrivateChat(System.currentTimeMillis());

		// 消息过滤
		msg = MmochatFilterService.getFilterString(msg);

		String myHint = "";
		try {
			if (msg.contains("#")) {
				for (int i = 0; i < 1; i++) {
					// #表1#~#表37# 替换成表情图标
					try {
						if (msg.contains("#表")) {
							Pattern equipPattern = Pattern.compile("#表[0-9]+#");
							Matcher matcher = equipPattern.matcher(msg);
							while (matcher.find()) {
								String equipStr = matcher.group();
								String equipPrueStr = equipStr.substring(2,
										equipStr.length() - 1);
								if (equipPrueStr.length() > 0) {
									try {
										int emotionId = Integer
												.parseInt(equipPrueStr);
										emotionId += MmochatConstant.BMP_EMOTION_1 - 1;
										if (emotionId >= MmochatConstant.BMP_EMOTION_1
												&& emotionId < MmochatConstant.BMP_EMOTION_MAX) {
											msg = msg
													.replaceFirst(
															equipStr,
															MmochatUtil
																	.wrapIcon(emotionId));
										}
									} catch (NumberFormatException e) {
										e.printStackTrace();
									}
								}
							}
						}
					} catch (Exception e3) {
					}

					// #当前坐标# 替换成实际坐标, 要求VIP
					try {
						if (msg.contains("#当前坐标#")) {
							MmochatMap curMap = MmochatMapService.getMapByMapId(me
									.getMapId());
							if (curMap != null) {
								String potisionMsg = curMap.getMapName();
								potisionMsg = potisionMsg.replaceAll("", "");
								potisionMsg = potisionMsg.replaceAll("", "");
								potisionMsg = potisionMsg.replaceAll("", "");
								potisionMsg = potisionMsg.replaceAll("", "");
								potisionMsg += (me.getLine() + 1) + "线";
								potisionMsg += "(" + me.getX() + "," + me.getY()
										+ ")";
								potisionMsg = MmochatUtil.wrapColor(potisionMsg,
										Color.cyan);
								msg = msg.replaceFirst("#当前坐标#", potisionMsg);
							}
						}
					} catch (Exception e2) {
					}

					// #我# 替换成自己的属性数据
					try {
						if (msg.contains("#我#")) {
							msg = msg.replaceFirst("#我#", "\n--------#我#--------\n"
									+ MmochatUtil.wrapColor("[人物属性]\n",
											Color.yellow)
									+ MmochatPlayerService.getUserAttrInfo(me)
									+ "\n--------#我#--------\n");
							myHint += "#我#替换为您的角色属性\n";
							break;
						}
					} catch (Exception e1) {
					}

					// #宠# 替换成参战宠物信息
					try {
						if (msg.contains("#宠#")) {
							MmochatPet pet = me.getPkPet();
							if (pet != null) {
								msg = msg.replaceFirst("#宠#",
										"\n--------#宠#--------\n"
												+ MmochatUtil.wrapColor("[参战宠物]\n",
														Color.yellow)
												+ pet.getPetDealInfo()
												+ "\n--------#宠#--------\n");
								myHint += "#宠#替换为您的参战宠物属性\n";
								break;
							}
						}
					} catch (Exception e1) {
					}

					// #[0-9]+# 替换成物品名
					Pattern equipPattern = Pattern.compile("#[0-9]+#");
					Matcher matcher = equipPattern.matcher(msg);
					if (matcher.find()) {
						String equipStr = matcher.group();
						String equipPrueStr = equipStr.substring(1, equipStr
								.length() - 1);
						if (equipPrueStr.length() > 0) {
							try {
								int gridId = Integer.parseInt(equipPrueStr);
								MmochatPackageGrid grid = me.getMyPackage()
										.get(gridId);
								if (grid != null && grid.getObject() != null) {
									MmochatCommonObject obj = grid.getObject();
									if (obj != null) {
										msg = msg
												.replaceFirst(
														equipStr,
														"\n--------"
																+ equipStr
																+ "--------\n"
																+ MmochatUtil
																		.wrapColor(
																				"["
																						+ obj
																								.getName()
																						+ "]\n",
																				Color.yellow)
																+ obj.getInfo()
																+ "\n--------"
																+ equipStr
																+ "--------\n");
										myHint += equipStr + "替换为您的["
												+ obj.getName() + "]属性\n";
									}
								}
							} catch (NumberFormatException e) {
							}
						}
						break;
					}
				}
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		String title = "";
		String dangerHint = "";
		if (he != null) {
			MmochatFriend frd = he.getMyDearFriends().get(me.getRoleId());
			if (frd != null) {
				title = "好友:";
			} else {
				title = "陌生人:";

				// 判断是否可能假冒对方好友
				if (!he.getMyDearFriends().containsKey(me.getRoleId())) {
					// me不是he的好友
					String name = me.getName();
					if (name.length() > 1) {
						// 检查me的名字与对方好友中的名字，相似度
						int maxSimilar = 0;
						String frdName = "";
						for (MmochatFriend mFrd : he.getMyDearFriends()
								.values()) {
							if (mFrd != null) {
								int sim = MmochatUtil.getSimilarity(name, mFrd
										.getName());
								if (sim > maxSimilar) {
									frdName = mFrd.getName();
									maxSimilar = sim;
								}
							}
						}
						if (maxSimilar > MmochatConstant.warnForDealSimilarity) {
							dangerHint = MmochatUtil.wrapColor(
									"\n注意:对方不是您的好友，但与您的好友", Color.green)
									+ MmochatUtil.wrapColor(frdName, Color.red)
									+ MmochatUtil.wrapColor("名字相似，",
											Color.green)
									+ MmochatUtil.wrapColor("小心假冒!", Color.red);
						}
					}
				}
			}
		}
		title += me.getName();
		String upperName = me.getName().toUpperCase();
		if ((upperName.contains("G") && upperName.contains("M"))
				|| (upperName.contains("客") && upperName.contains("服"))
				|| (upperName.contains("工") && upperName.contains("作"))
				|| (upperName.contains("克") && upperName.contains("服"))
				|| (upperName.contains("服") && upperName.contains("务"))
				|| (upperName.contains("服") && upperName.contains("器"))
				|| (upperName.contains("系") && upperName.contains("统"))) {
			dangerHint = MmochatUtil.wrapColor(
					"\n警告:对方可能假冒客服人员!聊天中请不要将账号密码或钱庄密码等信息告诉对方!", Color.red);
		}
		SimpleDateFormat sdf = new SimpleDateFormat("kk:mm:ss");
		String now = sdf.format(new Date());
		String wholeMsg = MmochatUtil.wrapColor(me.getName(), Color.yellow)
				+ " " + MmochatUtil.wrapColor(now, Color.green) + "\n" + msg
				+ dangerHint + "\n";

		if (he == null) {
			// 对方不在线，发送离线消息
			boolean ret = addPlayerOfflineMsgToFriend(req.getTargetRoleId(), me
					.getRoleId(), title, wholeMsg);
			if (ret) {
				if (!me.isAcceptStrangerMessage()) {
					if (me.getMyDearFriends().get(req.getTargetRoleId()) == null) {
						MmochatChatService.sendSystemMsgToPerson(me,
								MmochatUtil.wrapColor(
										"您已设置拒绝陌生人消息,对方不是您的好友,您可能无法收到对方的回复。",
										Color.green));
					}
				}

				try {
					// 记录私聊
					String chatKey;
					if (me.getRoleId() > req.getTargetRoleId()) {
						chatKey = me.getRoleId() + "+" + req.getTargetRoleId();
					} else {
						chatKey = req.getTargetRoleId() + "+" + me.getRoleId();
					}

					String chatLog = privateChatMap.get(chatKey);
					if (chatLog == null) {
						chatLog = "";
					}
					SimpleDateFormat time = new SimpleDateFormat("MM-dd HH:mm");
					String curTime = time.format(new Date());
					String chat = curTime + " " + me.getName() + ":" + msg
							+ "<br/>";
					chatLog += chat;
					privateChatMap.put(chatKey, chatLog);
				} catch (Exception e) {
				}

				return MmochatUtil
						.msgbox(
								req.getHallState(),
								"对方目前不在线，对方上线后会收到您的离线消息!离线消息将保留"
										+ (MmochatConstant.offlineMsgLife / MmochatConstant.MS_PER_HOUR)
										+ "小时!");
			} else {
				return MmochatUtil.msgbox(req.getHallState(),
						"对方目前不在线，对方的离线消息太多，暂时无法接收其它离线消息!");
			}
		}
		if (he.getMyEnermys().containsKey((me.getRoleId()))) {
			// 在对方黑名单
			return MmochatUtil.msgbox(req.getHallState(), "您在对方黑名单中,无法接收您的消息!");
		}
		if (!he.isAcceptStrangerMessage()) {
			if (he.getMyDearFriends().get(me.getRoleId()) == null) {
				// 拒绝陌生人消息
				return MmochatUtil.msgbox(req.getHallState(), "对方拒绝陌生人消息!");
			}
		}

		// 互相加为临时好友
		me.addTempFriend(he);
		he.addTempFriend(me);

		Mmochat_10_4S pack = new Mmochat_10_4S();
		pack.setSendRoleId(me.getRoleId());
		pack.setTitle(title);
		pack.setMsg(wholeMsg);
		MmochatUtil.sendCommonPack(he, pack);
		
		if (myHint.length()>0){
			String myTitle = "";
			MmochatFriend frd = me.getMyDearFriends().get(he.getRoleId());
			if (frd != null) {
				myTitle = "好友:";
			} else {
				myTitle = "陌生人:";
			}
			myTitle += he.getName();
			Mmochat_10_4S pack1 = new Mmochat_10_4S();
			pack1.setSendRoleId(he.getRoleId());
			pack1.setTitle(myTitle);
			pack1.setMsg(MmochatUtil.wrapColor(myHint, Color.magenta));
			MmochatUtil.sendCommonPack(me, pack1);
		}

		if (!me.isAcceptStrangerMessage()) {
			if (me.getMyDearFriends().get(he.getRoleId()) == null) {
				MmochatChatService.sendSystemMsgToPerson(me, MmochatUtil
						.wrapColor("您已设置拒绝陌生人消息,对方不是您的好友,您可能无法收到对方的回复。",
								Color.green));
			}
		}

		try {
			// 记录私聊
			String chatKey;
			if (me.getRoleId() > he.getRoleId()) {
				chatKey = me.getRoleId() + "+" + he.getRoleId();
			} else {
				chatKey = he.getRoleId() + "+" + me.getRoleId();
			}

			String chatLog = privateChatMap.get(chatKey);
			if (chatLog == null) {
				chatLog = "";
			}
			SimpleDateFormat time = new SimpleDateFormat("MM-dd HH:mm");
			String curTime = time.format(new Date());
			String chat = curTime + " " + me.getName() + ":" + msg + "<br/>";
			chatLog += chat;
			privateChatMap.put(chatKey, chatLog);
		} catch (Exception e) {
		}
		return null;
	}

	// 10.5 删除好友
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_5(SkymobiHandler handler,
			Mmochat_10_5C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return null;
		}
		if (req.getTargetRoleId() == me.getRoleId()) {
			return null;
		}
		MmochatFriend myFriend = me.getMyDearFriends().remove(
				req.getTargetRoleId());
		if (myFriend == null) {
			return null;
		}

		try {
			MmochatDao.updateMyFriends(me);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		MmochatPlayer he = MmochatMainService.getRoleFromBuffer(req
				.getTargetRoleId());
		if (he != null) {
			he.delFans(me.getRoleId());
		}
		me.delMyIdol(req.getTargetRoleId());

		return null;
	}

	// 10.6 加为好友
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_6(SkymobiHandler handler,
			Mmochat_10_6C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "跨服区内无法进行此操作!");
		}
		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());

		return addNewFriend(req.getHallState(), me, he);
	}

	// 10.7 清空临时好友列表
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_7(SkymobiHandler handler,
			Mmochat_10_7C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		me.getMyTempFriends().clear();

		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text("最近联系人已清空"));
		msgbox.setLeftName("确定");

		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_TEMPFRIEND), msgbox);
	}

	// 10.8 从好友或临时好友拉到黑名单
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_8(SkymobiHandler handler,
			Mmochat_10_8C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return null;
		}
		if (req.getTargetRoleId() == me.getRoleId()) {
			return null;
		}
		// 从临时好友终端影像中删除，因为终端已经直接删除了此临时好友
		me.getMyTempFriendsBak().remove(req.getTargetRoleId());

		// if (me.isEnermyFull()) {
		// return MmochatUtil.msgbox(req.getHallState(),
		// "您的黑名单已满,无法再增加黑名单,请先删除部分!");
		// }
		// 从好友中删除
		MmochatFriend enermy = me.getMyDearFriends().remove(
				req.getTargetRoleId());
		MmochatPlayer he = MmochatMainService.getRoleFromBuffer(req
				.getTargetRoleId());
		if (he != null) {
			he.delFans(me.getRoleId());
		}
		me.delMyIdol(req.getTargetRoleId());

		// 从临时好友中删除
		MmochatFriend enermy2 = me.getMyTempFriendsMap().get(
				req.getTargetRoleId());
		if (enermy == null) {
			enermy = enermy2;
		}
		if (enermy == null) {
			return null;
		}
		if (enermy2 != null) {
			me.getMyTempFriends().remove(enermy2);
			me.getMyTempFriendsMap().remove(enermy2.getRoleId());
		}

		boolean ret = me.addEnermy(enermy);
		if (ret) {
			try {
				MmochatDao.updateMyEnermys(me);
			} catch (Exception e) {
				e.printStackTrace();
				return MmochatUtil.msgbox(req.getHallState(), "数据库忙,请稍候再试!");
			}
			Mmochat_10_13S pack = new Mmochat_10_13S();
			pack.setEnermy(enermy);
			pack.setMe(me);
			MmochatUtil.sendCommonPack(me, pack);
		}
		return null;
	}

	// 10.9 从黑名单删除
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_9(SkymobiHandler handler,
			Mmochat_10_9C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (me.getMyEnermys().containsKey(req.getTargetRoleId())) {
			me.getMyEnermys().remove(req.getTargetRoleId());
			try {
				MmochatDao.updateMyEnermys(me);
			} catch (Exception e) {
				e.printStackTrace();
				return MmochatUtil.msgbox(req.getHallState(), "数据库忙,请稍候再试!");
			}
			// 下发
			Mmochat_10_14S pack = new Mmochat_10_14S();
			pack.setRoleId(req.getTargetRoleId());
			MmochatUtil.sendCommonPack(me, pack);
		} else {
			return MmochatUtil.msgbox(req.getHallState(), "此人不在黑名单中!");
		}
		return null;
	}

	// 10.10 清空黑名单
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_10(SkymobiHandler handler,
			Mmochat_10_10C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		me.getMyEnermys().clear();
		try {
			MmochatDao.updateMyEnermys(me);
		} catch (Exception e) {
			e.printStackTrace();
			return MmochatUtil.msgbox(req.getHallState(), "数据库忙,请稍候再试!");
		}
		// 下发
		Mmochat_10_15S pack = new Mmochat_10_15S();
		return pack;
	}

	// 10.17 飞到好友身边
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_17(SkymobiHandler handler,
			Mmochat_10_17C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (me.isInBattle()) {
			return null;
		}
		if (me.isInTeam()) {
			return MmochatUtil.msgbox(req.getHallState(), "组队时无法进行此操作!");
		}
		if (req.getTargetRoleId() == me.getRoleId()) {
			return MmochatUtil.msgbox(req.getHallState(), "不能对自己进行此操作!");
		}
		MmochatPlayer he = MmochatMainService.players
				.get(req.getTargetRoleId());
		if (he == null) {
			return MmochatUtil.msgbox(req.getHallState(), "对方目前不在线或已掉线,无法传送!");
		}
		if (MmochatMain.serverType == MmochatServerType.跨服战服务器) {
			return MmochatUtil.msgbox(req.getHallState(), "对方目前在跨服区,无法传送!");
		}

		if (me.hasYBTask()) {
			return MmochatUtil.msgbox(req.getHallState(),
					"押送镖银过程中无法飞到好友身边!您需要先放弃或完成此任务!");
		}

		MmochatPackageGrid grid = null;
		MmochatCommonObject prop = null;
		boolean free = false;
		if (me.getWife_roleId() == he.getRoleId()) {
			// 夫妻间传送，免费
			free = true;
		}

		if (!free) {
			if (he.getMyDearFriends().get(me.getRoleId()) != null) {
				// 互为好友，则优先考虑普通八挂令
				grid = me.getPackageGridOfObj(MmochatPropType.八卦令);
				if (grid == null || grid.getObject() == null
						|| grid.getObject().isUsedOut()) {
					// 没有普通八挂令，则使用超级八挂令
					grid = me.getPackageGridOfObj(MmochatPropType.超级八卦令);
				}
				if (grid == null || grid.getObject() == null
						|| grid.getObject().isUsedOut()) {
					return MmochatUtil.msgbox(req.getHallState(), "飞到好友身边需要借助"
							+ MmochatUtil.wrapColor("(超级)八卦令", Color.yellow)
							+ "的力量,按9键打开商城即可购买。");
				}
			} else {
				// 没加好友，则使用超级八挂令
				grid = me.getPackageGridOfObj(MmochatPropType.超级八卦令);
				if (grid == null || grid.getObject() == null
						|| grid.getObject().isUsedOut()) {
					return MmochatUtil.msgbox(req.getHallState(),
							"对方没加您为好友，飞到陌生人身边需要借助"
									+ MmochatUtil.wrapColor("超级八卦令",
											Color.yellow) + "的力量,按9键打开商城即可购买。");
				}
			}

			prop = grid.getObject();
			if (prop == null || prop.isUsedOut()) {
				return MmochatUtil.msgbox(req.getHallState(), "飞到好友身边需要借助"
						+ MmochatUtil.wrapColor("(超级)八卦令", Color.yellow)
						+ "的力量,按9键打开商城即可购买。");
			}
		}

		if (he.getLine() != me.getLine()) {
			return MmochatUtil.msgbox(req.getHallState(), "对方目前正在"
					+ (he.getLine() + 1) + "线,请先换线再飞行!");
		}

		MmochatMap curMap = MmochatMapService.getMapByMapId(me.getMapId());
		MmochatMap newMap = MmochatMapService.getMapByMapId(he.getMapId());

		if (!newMap.isCanTransToFriend()) {
			return MmochatUtil.msgbox(req.getHallState(), "对方所在地图不允许直接传送!");
		}

		if (!me.lockState(MmochatRoleStateType.飞到好友身边)) {
			MmochatChatService.sendSystemMsgToPerson(me, "当前无法进行飞行操作!请稍候再试。");
			return null;
		}
		if (me.isInBattle()) {
			me.unLockState();
			return null;
		}
		if (me.isInTeam()) {
			me.unLockState();
			return MmochatUtil.msgbox(req.getHallState(), "组队时无法进行此操作!");
		}
		if (he.getLine() != me.getLine()) {
			me.unLockState();
			return MmochatUtil.msgbox(req.getHallState(), "对方目前正在"
					+ (he.getLine() + 1) + "线,请先换线再飞行!");
		}

		if (!free) {
			// 扣除道具
			prop.use(1);
			if (prop.isUsedOut()) {
				grid.setObject(null);
				MmochatStatisticsService.addPropCost(prop.getPropType(), 1);
			}
			try {
				MmochatDao.updateMyPackage(me);
			} catch (Exception e1) {
				e1.printStackTrace();
				prop.use(-1);
				grid.setObject(prop);
				me.unLockState();
				return MmochatUtil.msgbox(req.getHallState(), "数据库忙,请稍候再试!");
			}

			// 更新包裹数据
			Mmochat_5_1S pack = new Mmochat_5_1S();
			pack.addGrid(grid);
			MmochatUtil.sendCommonPack(me, pack);
		}

		// 停止交易
		me.stopDeal();

		// 清除周围玩家
		me.getSceenRoles().clear();

		// 清除坐标缓存器
		me.getPositionBuffer().clear();

		// 清除NPC列表
		me.getTmpNpcs().clear();

		// 从旧的地图中移除
		if (newMap.getMapId() != curMap.getMapId()) {
			curMap.delRole(me.getLine(), me);
		}

		// 设置新坐标
		me.setX(he.getX());
		me.setY(he.getY());
		me.setMapId(he.getMapId());
		me.setLine(he.getLine());

		me.unLockState();

		Mmochat_1_1S pack1 = new Mmochat_1_1S();
		// 不使用hallState进行判断,以免终端连续上传两次请求后,终端hallState被第二次请求发送时更改
		pack1.setMap(newMap);
		pack1.setLine((int) me.getLine());
		pack1.setMe(me);
		pack1.setNeedCallBack(true);
		MmochatMainService.enterGame(me, me.getUserConnInfo(), pack1);
		synchronized (me) {
			// 坐标可能被其它线程修改，用同步保护
			me.setX(he.getX());
			me.setY(he.getY());
			MmochatUtil.sendCommonPack(me, pack1);
		}
		if (curMap.getMapId() != newMap.getMapId()) {
			try {
				MmochatDao.updateRoleEnterNewMap(me);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return null;
	}

	// 10.18 取消/关注好友
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_18(SkymobiHandler handler,
			Mmochat_10_18C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		if (req.getTargetRoleId() == me.getRoleId()) {
			return MmochatUtil.msgbox(req.getHallState(), "不能对自己进行此操作!");
		}
		String msg;
		Mmochat_10_12S pack = new Mmochat_10_12S();
		pack.setRoleId(req.getTargetRoleId());
		if (me.getMyIdols().containsKey(req.getTargetRoleId())) {
			// 取消关注
			me.delMyIdol(req.getTargetRoleId());
			msg = "您取消了对此好友的关注!";
			pack.setWatched(false);
		} else {
			// 增加关注
			me.addMyIdol(req.getTargetRoleId());
			msg = "您已关注此好友，对方上线或下线时您将收到系统消息提醒。";
			pack.setWatched(true);
		}
		// 下发更新好友状态
		MmochatUtil.sendCommonPack(me, pack);

		return MmochatUtil.msgbox(req.getHallState(), msg);
	}

	// 10.19 好友设置
	@SkymobiService
	public SkymobiProtocolMessage handleC_10_19(SkymobiHandler handler,
			Mmochat_10_19C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return MmochatUtil.msgbox(req.getHallState(), "服务器忙,请稍候再试!");
		}
		String msg = "";

		if (req.getIndex() == 0) {
			// 拒绝陌生人消息
			if (me.isAcceptStrangerMessage()) {
				me.setAcceptStrangerMessage(false);
				msg += "设置成功!当前状态下"
						+ MmochatUtil.wrapColor("拒绝接收陌生人消息", Color.green) + "。";
			} else {
				me.setAcceptStrangerMessage(true);
				msg += "设置成功!当前状态下"
						+ MmochatUtil.wrapColor("允许接收陌生人消息", Color.green) + "。";
			}
		} else if (req.getIndex() == 1) {
			// 添加好友验证
			if (me.isCheckAddMeFriend()) {
				me.setCheckAddMeFriend(false);
				msg += "设置成功!当前状态下其它人加您为好友时,"
						+ MmochatUtil.wrapColor("不需要征得您的同意", Color.green) + "。";
			} else {
				me.setCheckAddMeFriend(true);
				msg += "设置成功!当前状态下其它人加您为好友时,"
						+ MmochatUtil.wrapColor("需要征得您的同意", Color.green) + "。";
			}
		} else if (req.getIndex() == 2) {
			// 拒绝加为好友
			if (me.isAcceptAddMeFriend()) {
				me.setAcceptAddMeFriend(false);
				msg += "设置成功!当前状态下"
						+ MmochatUtil.wrapColor("其它人无法添加您为好友", Color.green)
						+ "。";
			} else {
				me.setAcceptAddMeFriend(true);
				msg += "设置成功!当前状态下"
						+ MmochatUtil.wrapColor("接受其它人添加您为好友的请求", Color.green)
						+ "。";
			}
		}

		ShowWaitingMsgBoxTLV wait = new ShowWaitingMsgBoxTLV();
		wait.setShowCancel(false);

		CreateTlvWin tlv = new CreateTlvWin();
		tlv.setWinType(WinType.List);
		tlv.setLeftName("切换");
		tlv.setRightName("返回");
		tlv.setTitle(MmochatQickStartType.好友设置.toString());
		tlv.setWinHeight(230);
		tlv.setWinId(MmochatConstant.TLV_WIN_SET_FRIEND);
		tlv.addRightTLV(new CloseWinTLV(MmochatConstant.TLV_WIN_SET_FRIEND));

		String item = "拒绝陌生人消息";
		if (me.isAcceptStrangerMessage()) {
			item += MmochatUtil.wrapColor("\n未开启", Color.yellow);
		} else {
			item += MmochatUtil.wrapColor("\n已开启", Color.yellow);
		}
		tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV((int) 0));

		item = "添加好友验证";
		if (me.isCheckAddMeFriend()) {
			item += MmochatUtil.wrapColor("\n已开启", Color.yellow);
		} else {
			item += MmochatUtil.wrapColor("\n未开启", Color.yellow);
		}
		tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV((int) 1));

		item = "拒绝加为好友";
		if (me.isAcceptAddMeFriend()) {
			item += MmochatUtil.wrapColor("\n未开启", Color.yellow);
		} else {
			item += MmochatUtil.wrapColor("\n已开启", Color.yellow);
		}
		tlv.addItemEvent(item, new ClearDataTLV(), new AddDataTLV((int) 2));

		tlv
				.addLeftTLV(new SendDataTLV(
						MmochatConstant.getClientModuleId(), MmochatMain
								.getModuleInstID(),
						MmochatConstant.MSGCODE_MMOCHAT_C_10_19, (int) req
								.getRoleId()));
		tlv.addLeftTLV(wait);

		CreateMsgBoxTLV msgbox = new CreateMsgBoxTLV();
		msgbox.setContent(new Text(msg));
		msgbox.setLeftName("确定");

		return MmochatUtil.tlvResponse(req.getHallState(), new CloseWinTLV(
				MmochatConstant.TLV_WIN_SET_FRIEND), tlv, msgbox);
	}

	// 10.21 加好友处理
	@SkymobiService
	public void handleC_10_21(SkymobiHandler handler, Mmochat_10_21C req) {
		MmochatPlayer me = MmochatMainService.getPlayerByRoleId(req, req
				.getRoleId());
		if (me == null) {
			return;
		}
		MmochatPlayer requester = MmochatMainService.getRoleFromBuffer(req
				.getTargetRoleId());
		if (requester == null) {
			return;
		}
		if (req.getTheResult() == 0) {
			// 同意
			if (requester.getMyEnermys().containsKey(me.getRoleId())) {
				// 从黑名单中删除
				requester.getMyEnermys().remove(me.getRoleId());
			}
			if (requester.isMyFriendsFull()) {
				sendSystemMsgToPersonByFriendMessage(requester, "您的好友列表已满，无法添加"
						+ me.getName() + "为好友。");
				return;
			}
			MmochatFriend newFriend = requester.addMyDearFriend(me);
			if (newFriend == null) {
				return;
			}
			try {
				MmochatDao.updateMyFriendsAndEnermys(requester);
			} catch (Exception e) {
				e.printStackTrace();
				return;
			}
			me.addFans(requester.getRoleId());

			Mmochat_10_11S pack = new Mmochat_10_11S();
			pack.setFriend(newFriend);
			pack.setMe(me);
			MmochatUtil.sendCommonPack(requester, pack);

			if (!requester.isAcceptAddMeFriend()) {
				MmochatChatService.sendSystemMsgToPerson(requester, MmochatUtil
						.wrapColor("您设置了拒绝加为好友,对方可能无法也加您为好友。", Color.green));
			}
			sendSystemMsgToPersonByFriendMessage(requester, me.getName()
					+ "已同意您加其好友。");
		} else {
			// 拒绝
			sendSystemMsgToPersonByFriendMessage(requester, me.getName()
					+ "拒绝您加其好友。");
		}
	}

	// 增加好友度:给所有相互是好友的玩家，增加一定的好友度
	public static void addFriendValue(Collection<MmochatPlayer> players, int add) {
		if (players == null || players.size() < 2) {
			return;
		}
		for (MmochatPlayer me : players) {
			for (MmochatPlayer he : players) {
				if (me.getRoleId() != he.getRoleId()) {
					MmochatFriend friend = me.getMyDearFriends().get(
							he.getRoleId());
					if (friend != null) {
						friend.addFriendValue(add);
					}
				}
			}
		}
	}
}
